/*
 * Copyright (c) 1994-2017, Joyoung Stock CO.LTD.
 * The FWJR Project.
 * All Rights Reserved.
 */

package com.rest.business;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException;
import com.rest.client.RestClient;
import com.rest.constant.JDConstant;
import com.rest.exception.BusinessException;
import com.rest.observer.FileDownLoadObserver;
import com.rest.response.AccountRespnonse;
import com.rest.response.AuthOauthVo;
import com.rest.response.BaseResponse;
import com.rest.response.BaseStringResponse;
import com.rest.response.ChatResponse;
import com.rest.response.CheckDetailResponse;
import com.rest.response.CheckResponse;
import com.rest.response.CloudListResponse;
import com.rest.response.ConsultOrderDetailResponse;
import com.rest.response.ConsultOrderFinishResponse;
import com.rest.response.ConsultOrderListResponse;
import com.rest.response.ConsultResponse;
import com.rest.response.ConsumablesAddDto;
import com.rest.response.ContactFindVO;
import com.rest.response.DiagnoseOrderDetailResponse;
import com.rest.response.DicResponse;
import com.rest.response.DocInfoResponse;
import com.rest.response.DocInfoVO;
import com.rest.response.DocOrderBaseVO;
import com.rest.response.DocOrderListVO;
import com.rest.response.DocScheduleVO;
import com.rest.response.DocStatusCountResponse;
import com.rest.response.DoctorResponse;
import com.rest.response.DrugResponse;
import com.rest.response.GroupResponse;
import com.rest.response.IMListResponse;
import com.rest.response.JCResponse;
import com.rest.response.JYResponse;
import com.rest.response.LoginResponse;
import com.rest.response.MedicineDetailResponse;
import com.rest.response.MedicineResponse;
import com.rest.response.MineResponse;
import com.rest.response.MouldListResponse;
import com.rest.response.MouldResponse;
import com.rest.response.NurseItemsVo;
import com.rest.response.OauthStatusResponse;
import com.rest.response.PatientListResponse;
import com.rest.response.PatientProjectDTO;
import com.rest.response.PatientResponse;
import com.rest.response.PicUploadResponse;
import com.rest.response.Prescription2Response;
import com.rest.response.PrescriptionDetailResponse;
import com.rest.response.PrescriptionListResponse;
import com.rest.response.PrescriptionResponse;
import com.rest.response.PrescriptionStatusDto;
import com.rest.response.QueryProtocolResponse;
import com.rest.response.RecordResponse;
import com.rest.response.RegistrationDetailResponse;
import com.rest.response.SickListResponse;
import com.rest.response.SignBean;
import com.rest.response.TeamDetailResponse;
import com.rest.response.TeamListResponse;
import com.rest.response.UserInfoBean;
import com.rest.response.VersionResponse;
import com.rest.util.JsonUtil;
import com.rest.util.MD5Coder;
import com.rest.util.RxUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import jz.joyoung.robot.util.LogUtil;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


public class RestProxy {
    private static final String TAG = "jd-" + RestProxy.class.getSimpleName();
    private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    private IRestAPI mRestApi;
    private Gson gson;

    private static class SingletonHolder {
        private static final RestProxy INSTANCE = new RestProxy();
    }

    /**
     * 获取单例
     */
    public static RestProxy getInstance() {
        return SingletonHolder.INSTANCE;
    }

    private RestProxy() {
        OkHttpClient okHttpClient = RestClient.getInstance().getOkHttpClient();

        Retrofit retrofitRms = new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(JDConstant.HOST)
                .addConverterFactory(GsonConverterFactory.create(buildGson()))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

        mRestApi = retrofitRms.create(IRestAPI.class);
    }

    /**
     * 增加后台返回""和"null"的处理
     * 1.int=>0
     * 2.double=>0.00
     * 3.long=>0L
     */
    private Gson buildGson() {
        if (gson == null) {
            gson = new GsonBuilder()
                    .registerTypeAdapter(Integer.class, new IntegerDefault0Adapter())
                    .registerTypeAdapter(int.class, new IntegerDefault0Adapter())
                    .registerTypeAdapter(Double.class, new DoubleDefault0Adapter())
                    .registerTypeAdapter(double.class, new DoubleDefault0Adapter())
                    .registerTypeAdapter(Long.class, new LongDefault0Adapter())
                    .registerTypeAdapter(long.class, new LongDefault0Adapter())
                    .create();
        }
        return gson;
    }

    public static class IntegerDefault0Adapter implements JsonSerializer<Integer>, JsonDeserializer<Integer> {

        @Override
        public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                throws JsonParseException {
            try {
                if ("".equals(json.getAsString()) || "null".equals(json.getAsString())) {
                    //定义为int类型,如果后台返回""或者null,则返回0
                    return 0;
                }
            } catch (Exception ignore) {
            }
            try {
                return json.getAsInt();
            } catch (NumberFormatException e) {
                throw new JsonSyntaxException(e);
            }
        }

        @Override
        public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
            return new JsonPrimitive(src);
        }
    }

    public static class LongDefault0Adapter implements JsonSerializer<Long>, JsonDeserializer<Long> {

        @Override
        public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                throws JsonParseException {
            try {
                if ("".equals(json.getAsString()) || "null".equals(json.getAsString())) {
                    //定义为long类型,如果后台返回""或者null,则返回0
                    return Long.valueOf(0);
                }
            } catch (Exception ignore) {
            }
            try {
                return json.getAsLong();
            } catch (NumberFormatException e) {
                throw new JsonSyntaxException(e);
            }
        }

        @Override
        public JsonElement serialize(Long src, Type typeOfSrc, JsonSerializationContext context) {
            return new JsonPrimitive(src);
        }
    }

    public static class DoubleDefault0Adapter implements JsonSerializer<Double>, JsonDeserializer<Double> {

        @Override
        public Double deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                throws JsonParseException {
            try {
                if ("".equals(json.getAsString()) || "null".equals(json.getAsString())) {
                    //定义为double类型,如果后台返回""或者null,则返回0.00
                    return 0.00;
                }
            } catch (Exception ignore) {
            }
            try {
                return json.getAsDouble();
            } catch (NumberFormatException e) {
                throw new JsonSyntaxException(e);
            }
        }

        @Override
        public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) {
            return new JsonPrimitive(src);
        }
    }


    /**
     * 生成签名
     */
    private String getSign(String str, byte[] data, String salt) {
        if (TextUtils.isEmpty(str)) {
            LogUtil.w(TAG, "Empty param!");
            return null;
        }

        byte[] strBytes;
        byte[] saltBytes;
        try {
            saltBytes = salt.getBytes("UTF-8");
            strBytes = str.getBytes("UTF-8");
        } catch (UnsupportedEncodingException | NullPointerException e) {
            e.printStackTrace();
            return null;
        }

        int strLength = strBytes.length;
        int dataLength = data == null ? 0 : data.length;
        int saltLength = saltBytes.length;
        byte[] valuesBytes = new byte[strLength + dataLength + saltLength];
        System.arraycopy(strBytes, 0, valuesBytes, 0, strLength);
        if (dataLength > 0) {
            System.arraycopy(data, 0, valuesBytes, strLength, dataLength);
        }
        System.arraycopy(saltBytes, 0, valuesBytes, strLength + dataLength, saltLength);
        MD5Coder md5Coder = new MD5Coder();
        return md5Coder.encrypt2Str(valuesBytes);
    }

    /**
     * 封装RequestBody
     */
    RequestBody getRequestBody(String str) {
        return RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str);
    }

    public void login(String username, String password, String mobileNum, Observer<LoginResponse> subscriber) {

        RequestBody requestBody = new FormBody.Builder()
                .add("userName", username)
                .add("password", password)
                .build();

        mRestApi.login(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getUserInfo(Observer<DocInfoVO> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .build();

        mRestApi.getUserInfo(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void saveUserInfo(int editType, String editData, Observer<BaseResponse> subscriber) {
        RequestBody requestBody = null;
        if (editType == 1) {
            requestBody = new FormBody.Builder()
                    .add("name", editData)
                    .build();
        } else if (editType == 2) {
            requestBody = new FormBody.Builder()
                    .add("introduction", editData)
                    .build();
        } else if (editType == 3) {
            requestBody = new FormBody.Builder()
                    .add("goodAt", editData)
                    .build();
        }


        mRestApi.saveUserInfo(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void uploadFile(String bucket, String type, String relationId, File file1, Observer<PicUploadResponse> subscriber) {
        MultipartBody.Builder multipartBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("bucket", bucket)
                .addFormDataPart("type", type)
//                .addFormDataPart( "relationId", "1" )
                .addFormDataPart("relationId", relationId)
                .addFormDataPart("checkStatus", "0");

        if (file1 != null) {
            multipartBody.addFormDataPart("file", file1.getName(), RequestBody.create(MediaType.parse("image/jpg"), file1));
        }


        RequestBody requestBody = multipartBody.build();


        mRestApi.uploadFile(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getPresignedUrl(String bucket, Observer<BaseStringResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("bucket", bucket)
                .build();


        mRestApi.getPresignedUrl(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void uploadVideo(File file1, Observer<PicUploadResponse> subscriber) {
        MultipartBody.Builder multipartBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("bucket", "9")
                .addFormDataPart("type", "93");
//                .addFormDataPart("relationId", "1")
//                .addFormDataPart("checkStatus", "0");

        if (file1 != null) {
            multipartBody.addFormDataPart("file", file1.getName(), RequestBody.create(MediaType.parse("application/octet-stream"), file1));
        }


        RequestBody requestBody = multipartBody.build();


        mRestApi.uploadVideo(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void downloadFile(String url, final String destDir, final String fileName, final FileDownLoadObserver<File> fileDownLoadObserver) {
        mRestApi.downloadFile(url).map(responseBody -> fileDownLoadObserver.saveFile(responseBody, destDir, fileName)).subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(fileDownLoadObserver);
    }


    public void updatePassword(String password, String newPassword, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("password", password)
                .add("newPassword", newPassword)
                .build();

        mRestApi.updatePassword(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getCode(String phone, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("phone", phone)
                .build();

        mRestApi.getMessageCode(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void register(String name, String idcard, String password, String code, String phone, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("phone", phone)
                .add("name", name)
                .add("idcard", idcard)
                .add("password", password)
                .add("code", code)
                .build();

        mRestApi.register(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void queryIMList(String doctorUserId, String flag, Observer<IMListResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("doctorUserId", doctorUserId)
                .add("flag", flag)
                .add("current", "1")
                .add("size", "100")
                .build();

        mRestApi.queryIMList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void queryHistoryIMList(String doctorUserId, Observer<IMListResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("doctorUserId", doctorUserId)
                .add("current", "1")
                .add("size", "100")
                .build();

        mRestApi.queryHistoryIMList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getDepartmentList(String name, Observer<DoctorResponse> subscriber) {
        FormBody.Builder requestBody = new FormBody.Builder();
        if (!TextUtils.isEmpty(name)) {
            requestBody.add("name", name);
        }


        mRestApi.getDepartmentList(requestBody.build())
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getDoctorList(String id, Observer<DoctorResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", id)
                .build();

        mRestApi.getDoctorList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getChatList(String diagnoseId, String current, Observer<ChatResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("diagnoseId", diagnoseId)
                .add("current", current)
                .add("size", "100")
                .build();

        mRestApi.getChatList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getRegistrationDetail(String patientUserId, String diagnoseId, Observer<RegistrationDetailResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
//                .add("patientUserId", patientUserId)
                .add("diagnoseId", diagnoseId)
                .build();

        mRestApi.getRegistrationDetail(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void savePatientState(String patientId, String receiverDocId, String oneselfState, String resourceIdList, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("patientId", patientId)
                .add("receiverDocId", receiverDocId)
                .add("oneselfState", oneselfState)
                .add("resourceIdList", resourceIdList)
                .build();

        mRestApi.savePatientState(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getCheckList(String status, String type, Observer<CheckResponse> subscriber) {

        Map<String, Object> map = new HashMap<>();//body  map
        map.put("status", status);
        map.put("type", type);
        map.put("startTime", "");
        map.put("endTime", "");
        map.put("condition", "");
        map.put("current", "1");
        map.put("size", "50");
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);

        mRestApi.getCheckList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void queryPrescriptionList(String diagnoseId, Observer<PrescriptionListResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", diagnoseId)
                .build();

        mRestApi.queryPrescriptionList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getPrescription(String prescriptionId, Observer<PrescriptionResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", prescriptionId)
                .build();

        mRestApi.getPrescription(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getPrescription2(String preId, Observer<Prescription2Response> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", preId)
                .build();

        mRestApi.getPrescription2(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void delPrescription(String prescriptionId, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", prescriptionId)
                .build();

        mRestApi.delPrescription(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void check(String id, String status, String reject, Observer<BaseResponse> subscriber) {

        Map<String, Object> map = new HashMap<>();//body  map
        map.put("id", id);
        map.put("status", status);
        map.put("reject", reject);
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);

        mRestApi.check(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getMouldList(String condition, Observer<MouldResponse> subscriber) {

        Map<String, Object> map = new HashMap<>();//body  map
        map.put("condition", condition);
        map.put("size", "50");
        map.put("current", "1");
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);

        mRestApi.getMouldList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getMedicineList(String id, String content, String type, Observer<MedicineResponse> subscriber) {

        RequestBody requestBody = new FormBody.Builder()
                .add("id", id)
                .add("content", content)
                .add("type", type)
                .build();

        mRestApi.getMedicineList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void queryWesternById(String id, Observer<MedicineDetailResponse> subscriber) {

        mRestApi.queryWesternById(id)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void queryRouteAndSiteById(String type, String id, String helpCode, Observer<DicResponse> subscriber) {

        mRestApi.queryRouteAndSiteById(type, id, helpCode)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void queryPrice(String id, String number, Observer<BaseStringResponse> subscriber) {

        mRestApi.queryPrice(id, number)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getDicList(String helpCode, String category, Observer<DicResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("helpCode", helpCode)
                .add("category", category)
                .build();

        mRestApi.getDicList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void savePrescriptionModel(String presciptionModelId, String modelName, String advice, String remark, String preAppendId, String icdId, String tailAppendId, String type, List<PrescriptionResponse.Prescription> list, List<PrescriptionResponse.Second> list2, Observer<BaseResponse> subscriber) {

        Map<String, Object> map = new HashMap<>();//body  map
        map.put("presciptionModelId", presciptionModelId);
        map.put("modelName", modelName);
        map.put("advice", advice);
        map.put("remark", remark);
        map.put("isChildren", "0");
        map.put("preAppendId", preAppendId);
        map.put("icdId", icdId);
        map.put("tailAppendId", tailAppendId);
        map.put("westernVoList", list);
        map.put("secondList", list2);
        map.put("type", type);
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);

        mRestApi.savePrescriptionModel(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void savePrescription(String diagnoseId, String advice, String remark, String presciptionId, String preAppendId, String icdId, String tailAppendId, String isChildren, String type, List<PrescriptionResponse.Prescription> list, List<PrescriptionResponse.Second> list2, Observer<BaseResponse> subscriber) {

        Map<String, Object> map = new HashMap<>();//body  map
        map.put("diagnoseId", diagnoseId);
        map.put("feedback", advice);
        map.put("remark", remark);
        map.put("isChildren", isChildren);
        map.put("presciptionId", presciptionId);
        map.put("preAppendId", preAppendId);
        map.put("icdId", icdId);
        map.put("tailAppendId", tailAppendId);
        map.put("westernVoList", list);
        map.put("secondList", list2);
        map.put("type", type);
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);

        mRestApi.savePrescription(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void savePrescriptionList(String diagnoseId, String remark, String presciptionId, String type, List<PrescriptionListResponse.Prescription> list, Observer<BaseStringResponse> subscriber) {

        Map<String, Object> map = new HashMap<>();//body  map
        map.put("diagnoseId", diagnoseId);
        map.put("remark", remark);
        map.put("presciptionId", presciptionId);
        map.put("westernVoList", list);
        map.put("type", type);

        mRestApi.savePrescription(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getPrescriptionModel(String prescriptionId, Observer<MouldResponse> subscriber) {


        mRestApi.getPrescriptionModel(prescriptionId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getPrescriptionModelList(String prescriptionId, Observer<MouldListResponse> subscriber) {


        mRestApi.getPrescriptionModelList(prescriptionId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getRefusePrescription(Observer<IMListResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("size", "100")
                .add("current", "1")
                .build();

        mRestApi.getRefusePrescription(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void finishDiagnose(String diagnoseId, String patientUserId, Observer<BaseResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("diagnoseId", diagnoseId)
                .add("patientUserId", patientUserId)
                .build();

        mRestApi.finishDiagnose(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getSickList(String content, Observer<SickListResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("helpCode", content)
//                .add("patientUserId", patientUserId)
                .build();

        mRestApi.getSickList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void accpetConsultation(String flag, Observer<BaseResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("flag", flag)
                .build();

        mRestApi.accpetConsultation(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getMineInfo(Observer<MineResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .build();

        mRestApi.getMineInfo(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void acceptDiagnose(String diagnoseId, String status, Observer<BaseResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("diagnoseId", diagnoseId)
                .add("status", status)
                .build();

        mRestApi.acceptDiagnose(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getDocInfo(Observer<DocInfoResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
//                .add("diagnoseId", diagnoseId)
//                .add("status", status)
                .build();

        mRestApi.getDocInfo(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getDocCountStatus(Observer<DocStatusCountResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
//                .add("diagnoseId", diagnoseId)
//                .add("status", status)
                .build();

        mRestApi.getDocCountStatus(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getGroupList(Observer<GroupResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
//                .add("diagnoseId", diagnoseId)
//                .add("status", status)
                .build();

        mRestApi.getGroupList()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getPatientInfo(String id, Observer<PatientResponse> subscriber) {
        mRestApi.getPatientInfo(id)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getGroupInfo(Observer<GroupResponse> subscriber) {
        mRestApi.getGroupInfo()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void addGroup(String groupName, Observer<BaseResponse> subscriber) {
        mRestApi.addGroup(groupName)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void delGroup(String id, Observer<BaseResponse> subscriber) {
        mRestApi.delGroup(id)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void searchPatientList(String id, Observer<PatientListResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
//                .add("diagnoseId", diagnoseId)
//                .add("status", status)
                .build();

        mRestApi.searchPatientList(id)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void updatePatientGroup(String tbPatientId, String id, Observer<BaseResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
//                .add("diagnoseId", diagnoseId)
//                .add("status", status)
                .build();

        mRestApi.updatePatientGroup(tbPatientId, id)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void updateTop(String diagnoseId, String status, Observer<BaseResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("diagnoseId", diagnoseId)
                .add("status", status)
                .add("userType", "1")
                .build();

        mRestApi.updateTop(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getTeamList(Observer<TeamListResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("type", "1")
                .build();

        mRestApi.getTeamList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getTeamDetail(String id, Observer<TeamDetailResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("id", id)
                .build();

        mRestApi.getTeamDetail(id)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getDoctorByName(String name, Observer<DoctorResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("name", name)
                .build();

        mRestApi.getDoctorByName(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void updateUmengDevice(String mobileNum, String mobileType, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("mobileNum", mobileNum)
                .add("mobileType", mobileType)
                .build();

        mRestApi.updateUmengDevice(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void addTeamMember(String id, String doctorId, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", id)
                .add("doctorId", doctorId)
                .build();

        mRestApi.addTeamMember(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void delTeamMember(String id, String doctorId, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", id)
                .add("doctorId", doctorId)
                .build();

        mRestApi.delTeamMember(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void updateTeamDetail(String id, String name, String description, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", id)
                .add("name", name)
                .add("description", description)
                .build();

        mRestApi.updateTeamDetail(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void finishMeeting(String patientUserId, String diagnoseId, String doctorUserId, String conferenceId, String meetingType, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("patientUserId", patientUserId)
                .add("diagnoseId", diagnoseId)
                .add("doctorUserId", doctorUserId)
                .add("conferenceId", conferenceId)
                .add("meetingType", meetingType)
                .add("systemType", "1")
                .build();

        mRestApi.finishMeeting(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getRecord(String id, Observer<RecordResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", id)
                .add("size", "1000")
                .add("current", "1")
                .build();

        mRestApi.getRecord(id, 1000 + "", 1 + "")
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void diagnoseOrderDetail(String diagnoseId, Observer<DiagnoseOrderDetailResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("diagnoseId", diagnoseId)
                .build();

        mRestApi.diagnoseOrderDetail(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void delMould(String id, Observer<BaseResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
//                .add("diagnoseId", diagnoseId)
//                .add("status", status)
                .build();

        mRestApi.delMould(id)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void queryProtocol(String rulesType, Observer<QueryProtocolResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("type", rulesType)
                .build();

        mRestApi.queryProtocol(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getCloudList(String flag, Observer<CloudListResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("flag", flag)
                .add("current", "0")
                .add("size", "100")
                .build();

        mRestApi.getCloudList(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void sendSms(String outpId, String type, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("outpId", outpId)
                .add("type", type)
                .build();

        mRestApi.sendSms(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void backPrescription(String id, String type, Observer<BaseResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
//                .add("diagnoseId", diagnoseId)
//                .add("status", status)
                .build();

        mRestApi.backPrescription(id, type)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void saveCase(Map<String, Object> map, Observer<BaseResponse> subscriber) {

        mRestApi.saveCase(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getCase(String diagnoseId, String patientId, Observer<PrescriptionResponse> subscriber) {
        Map<String, Object> map = new HashMap<>();//body  map
        map.put("diagnoseId", diagnoseId);
        map.put("patientId", patientId);
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);

        mRestApi.getCase(diagnoseId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void changeFlag(String id, String flag, Observer<BaseResponse> subscriber) {


        RequestBody requestBody = new FormBody.Builder()
                .add("id", id)
                .add("flag", flag)
                .build();

        mRestApi.changeFlag(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getVersion(Observer<VersionResponse> subscriber) {

        RequestBody requestBody = new FormBody.Builder()
                .add("source", "1")
                .add("type", "1")
                .build();

        mRestApi.getVersion(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void uploadFileTb(String bucket, String type, String objectName, String relationId, String fileSize, String isIm, Observer<PicUploadResponse> subscriber) {
        // bucket:   1-病历 2-评论(反馈) 3-头像 4-轮播图 9-聊天图片 ',
        // type:   15-病历 2-评论(反馈) 30-头像 92-聊天图片 ',
        //relationId病例id  患者自述默认 1 医生头像为医生id，用户头像为用户id
        Map<String, Object> map = new HashMap<>();//body  map

        map.put("bucket", bucket);
        map.put("type", type);
        map.put("objectName", objectName);
        map.put("introduction", "image/png");
        map.put("relationId", relationId);
        map.put("size", fileSize);
        map.put("isIm", isIm);
        map.put("checkStatus", "0");
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);


        mRestApi.uploadFileTb(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getPatientAccount(String diagnoseId, String type, Observer<AccountRespnonse> subscriber) {

        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("diagnoseId", diagnoseId);
            jsonObject.put("type", type);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        mRestApi.getPatientAccount(getRequestBody(jsonObject.toString()))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getMedicineOrderDetail(String orderId, Observer<PrescriptionDetailResponse> subscriber) {
        RequestBody requestBody = new FormBody.Builder()
                .add("orderId", orderId)
                .build();

        mRestApi.getMedicineOrderDetail(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getWaitListCount(Observer<BaseStringResponse> subscriber) {

        mRestApi.getWaitListCount()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getOrderListCount(Observer<BaseStringResponse> subscriber) {

        mRestApi.getOrderListCount()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getMySchedule(String date, Observer<DocScheduleVO> subscriber) {

        Map<String, Object> map = new HashMap<>();
        map.put("date", date);

        mRestApi.getMySchedule(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void addContact(Map<String, Object> map, Observer<BaseResponse> subscriber) {


        mRestApi.addContact(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void findContact(Observer<ContactFindVO> subscriber) {


        mRestApi.findContact()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void oneKeyAlarm(Map<String, Object> map, Observer<BaseResponse> subscriber) {

        mRestApi.oneKeyAlarm(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void currentPatientList(Observer<DocOrderBaseVO> subscriber) {


        mRestApi.currentPatientList()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void cancelForDoc(Map<String, Object> map, Observer<BaseResponse> subscriber) {

        mRestApi.cancelForDoc(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void updateDocSetOut(String type, String docAppointmentId, String conclusion, Observer<BaseResponse> subscriber) {
        Map<String, Object> map = new HashMap<>();
        map.put("type", type);
        map.put("docAppointmentId", docAppointmentId);
        map.put("conclusion", conclusion);

        mRestApi.updateDocSetOut(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getOrderList(String current, Observer<DocOrderListVO> subscriber) {
        Map<String, Object> map = new HashMap<>();
        map.put("current", current);
        map.put("size", "10");

        mRestApi.getOrderList(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getWaitList(String current, Observer<DocOrderListVO> subscriber) {
        Map<String, Object> map = new HashMap<>();
        map.put("current", current);
        map.put("size", "10");

        mRestApi.getWaitList(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void appointmentDetail(String appointmentId, Observer<PatientProjectDTO> subscriber) {


        mRestApi.appointmentDetail(appointmentId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void updateForOrder(Map<String, Object> map, Observer<BaseResponse> subscriber) {

        mRestApi.updateForOrder(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getHisOrderList(Map<String, Object> map, Observer<DocOrderListVO> subscriber) {


        mRestApi.getHisOrderList(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getOrderDoneCount(Map<String, Object> map, Observer<BaseStringResponse> subscriber) {

        mRestApi.getOrderDoneCount(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getCancelCount(Map<String, Object> map, Observer<BaseStringResponse> subscriber) {

        mRestApi.getCancelCount(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void nurseItemList(Observer<NurseItemsVo> subscriber) {


        mRestApi.nurseItemList("2")
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void addConsumables(Map<String, Object> map, Observer<ConsumablesAddDto> subscriber) {

        mRestApi.addConsumables(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void cancelConsumables(String orderId, Observer<BaseResponse> subscriber) {

        mRestApi.cancelConsumables(orderId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void updateTime(String id, String appointmentTime, Observer<BaseResponse> subscriber) {

        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("appointmentTime", appointmentTime);

        mRestApi.updateTime(JsonUtil.listToJson(map))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void userSignature(String redirectURL, Observer<SignBean> subscriber) {
        Map<String, Object> map = new HashMap<>();//body  map
        map.put("redirectURL", redirectURL);

        String json = new Gson().toJson(map);

        RequestBody requestBody = RequestBody.create(JSON, json);

        mRestApi.userSignature(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }


    public void querySignStatus(String userId, Observer<UserInfoBean> subscriber) {
        Map<String, Object> map = new HashMap<>();//body  map
        map.put("userId", userId);
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);
        mRestApi.querySignStatus(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }

    public void queryPrescriptionStatus(String prescriptionId, Observer<PrescriptionStatusDto> subscriber) {
        mRestApi.queryPrescriptionStatus(prescriptionId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }

    public void submitPrescriptionSecond(String prescriptionId, Observer<BaseStringResponse> subscriber) {
        mRestApi.submitPrescriptionSecond(prescriptionId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }

    public void queryOauthStatus(Observer<OauthStatusResponse> subscriber) {
        mRestApi.queryOauthStatus()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }


    public void authOauth(Observer<AuthOauthVo> subscriber) {
        Map<String, Object> map = new HashMap<>();//body  map
        map.put("userId", 2);
        map.put("redirectURL", "https://ysg.com/auth");
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);
        mRestApi.authOauth(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }

    public void wxLogin(String code, Observer<LoginResponse> subscriber) {
        mRestApi.wxLogin(code)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }

    public void searchDrug(String keyWords, int page, Observer<DrugResponse> subscriber) {
        mRestApi.searchDrug(keyWords, page)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }

    public void validateInfo(String code, String phone, String userName, Observer<BaseResponse> subscriber) {
//        Map<String, Object> map = new HashMap<>();//body  map
//        map.put("code", code);
//        map.put("phone", phone);
//        map.put("userName", userName);

//        String json = new Gson().toJson(map);
//        RequestBody requestBody = RequestBody.create(JSON, json);
        mRestApi.validateInfo(code, phone, userName)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }

    public void modifyPassword(String docCode, String password, Observer<BaseResponse> subscriber) {
        mRestApi.modifyPassword(docCode, password)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }

    public void refund(String orderNumber, String refundReason, Observer<BaseResponse> subscriber) {
        Map<String, Object> map = new HashMap<>();//body  map
        map.put("orderNumber", orderNumber);
        map.put("refundReason", refundReason);
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);
        mRestApi.refund(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .compose(RxUtil.applySchedulers())
                .subscribe(subscriber);
    }


    public void getConsultListCount(Observer<ConsultResponse> subscriber) {

        mRestApi.getConsultListCount()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);
                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void queryConsultOrderList(String nurseId, String status, Observer<ConsultOrderListResponse> subscriber) {

        mRestApi.queryConsultOrderList(nurseId, status, "100")
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getConsultOrderDetailInfo(String diagnoseId, Observer<ConsultOrderDetailResponse> subscriber) {

        mRestApi.getConsultOrderDetailInfo(diagnoseId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void consultOrderFinish(String diagnoseId, Observer<ConsultOrderFinishResponse> subscriber) {

        mRestApi.consultOrderFinish(diagnoseId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void acceptConsultOrder(String diagnoseId, Observer<BaseResponse> subscriber) {

        mRestApi.acceptConsultOrder(diagnoseId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void refuseConsultOrder(String diagnoseId, Observer<BaseResponse> subscriber) {

        mRestApi.refuseConsultOrder(diagnoseId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void consultOrderRefund(String diagnoseId, String reason, Observer<BaseResponse> subscriber) {

        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("diagnoseId", diagnoseId);
            jsonObject.put("reason", reason);
        } catch (Exception e) {
            e.printStackTrace();
        }

        mRestApi.consultOrderRefund(getRequestBody(jsonObject.toString()))
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void electronicSignature(String preId, Observer<BaseStringResponse> subscriber) {
        mRestApi.electronicSignature(preId)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);

    }

    public void getJCListData(Observer<JCResponse> subscriber) {
        mRestApi.getJCListData()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void getJYListData(Observer<JYResponse> subscriber) {
        mRestApi.getJYListData()
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    public void billing(Map<String,Object> map, Observer<BaseResponse> subscriber) {
        String json = new Gson().toJson(map);
        RequestBody requestBody = RequestBody.create(JSON, json);
//        JSONObject jsonObject = new JSONObject();
//        try {
//            jsonObject.put("diagnoseId", diagnoseId);
//            jsonObject.put("jcList", reason);
//            jsonObject.put("jyList", reason);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

//        mRestApi.billing(getRequestBody(jsonObject.toString()))
        mRestApi.billing(requestBody)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void getCheckoutDetail(String id, Observer<CheckDetailResponse> subscriber) {
        mRestApi.getCheckoutDetail(id)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }


    public void changeStatus(String id,int type,Observer<BaseStringResponse> subscriber) {
        mRestApi.changeStatus(id,type)
                .map(response -> {
                    LogUtil.d(TAG, "Response => " + response);

                    if (!response.isSuccessful()) {
                        LogUtil.d(TAG, "Response => " + response.message);
                        throw new BusinessException(response.code, response.message);
                    }
                    return response;
                })
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

}
